Convert GailScaleButton to GtkScaleButtonAccessible
authorMatthias Clasen <mclasen@redhat.com>
Wed, 29 Jun 2011 02:45:42 +0000 (22:45 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Jul 2011 20:08:54 +0000 (16:08 -0400)
gtk/a11y/Makefile.am
gtk/a11y/gail.c
gtk/a11y/gtkscalebuttonaccessible.c [new file with mode: 0644]
gtk/a11y/gtkscalebuttonaccessible.h [new file with mode: 0644]
gtk/gtkscalebutton.c

index deab12cde8626dc0354d8695f12780b48d7136f1..00c2eea592dbf8c2e464b90813f4590c8cf1df22 100644 (file)
@@ -36,7 +36,7 @@ gail_c_sources =                      \
        gtkrangeaccessible.c            \
        gailrenderercell.c              \
        gtkscaleaccessible.c            \
-       gailscalebutton.c               \
+       gtkscalebuttonaccessible.c      \
        gtkscrollbaraccessible.c        \
        gailscrolledwindow.c            \
        gtkspinbuttonaccessible.c       \
@@ -87,7 +87,7 @@ gail_private_h_sources =              \
        gtkrangeaccessible.h            \
        gailrenderercell.h              \
        gtkscaleaccessible.h            \
-       gailscalebutton.h               \
+       gtkscalebuttonaccessible.h      \
        gtkscrollbaraccessible.h        \
        gailscrolledwindow.h            \
        gtkspinbuttonaccessible.h       \
@@ -131,7 +131,7 @@ libgail_la_CFLAGS = \
        $(AM_CFLAGS)
 
 libgail_la_LIBADD =  \
-       $(GTK_DEP_LIBS)                                         \
+       $(GTK_DEP_LIBS)         \
        $(INTLLIBS)
 
 libgail_la_LDFLAGS =    \
index 0d13b2fdde55bcf6c63010a07d91e308e15d897e..18c8b2a619da2a59f6071a115c948621db8dabf5 100644 (file)
@@ -38,7 +38,6 @@
 #include "gailnotebook.h"
 #include "gailradiomenuitem.h"
 #include "gailrenderercell.h"
-#include "gailscalebutton.h"
 #include "gailscrolledwindow.h"
 #include "gailstatusbar.h"
 #include "gailtextcell.h"
@@ -102,7 +101,6 @@ GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_COMBO_BOX, GailComboBox, gail_combo_box, GTK_T
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU_SHELL, GailMenuShell, gail_menu_shell, GTK_TYPE_MENU_SHELL)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU, GailMenu, gail_menu, GTK_TYPE_MENU)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WINDOW, GailWindow, gail_window, GTK_TYPE_BIN)
-GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_SCALE_BUTTON, GailScaleButton, gail_scale_button, GTK_TYPE_SCALE_BUTTON)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_STATUSBAR, GailStatusbar, gail_statusbar, GTK_TYPE_STATUSBAR)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_NOTEBOOK, GailNotebook, gail_notebook, GTK_TYPE_NOTEBOOK)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_TREE_VIEW, GailTreeView, gail_tree_view, GTK_TYPE_TREE_VIEW)
@@ -862,7 +860,6 @@ gail_accessibility_module_init (void)
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_BAR, gail_menu_shell);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU, gail_menu);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_WINDOW, gail_window);
-  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_SCALE_BUTTON, gail_scale_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_STATUSBAR, gail_statusbar);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_NOTEBOOK, gail_notebook);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_TREE_VIEW, gail_tree_view);
diff --git a/gtk/a11y/gtkscalebuttonaccessible.c b/gtk/a11y/gtkscalebuttonaccessible.c
new file mode 100644 (file)
index 0000000..60592c3
--- /dev/null
@@ -0,0 +1,258 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2008 Jan Arne Petersen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include "gtkscalebuttonaccessible.h"
+
+#include <string.h>
+
+
+static void atk_action_interface_init (AtkActionIface *iface);
+static void atk_value_interface_init  (AtkValueIface  *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkScaleButtonAccessible, gtk_scale_button_accessible, GAIL_TYPE_BUTTON,
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init));
+
+static void
+gtk_scale_button_accessible_value_changed (GtkAdjustment *adjustment,
+                                           gpointer       data)
+{
+  g_object_notify (G_OBJECT (data), "accessible-value");
+}
+
+static void
+gtk_scale_button_accessible_initialize (AtkObject *obj,
+                                        gpointer   data)
+{
+  GtkAdjustment *adjustment;
+
+  ATK_OBJECT_CLASS (gtk_scale_button_accessible_parent_class)->initialize (obj, data);
+
+  adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (data));
+  if (adjustment)
+    g_signal_connect (adjustment,
+                      "value-changed",
+                      G_CALLBACK (gtk_scale_button_accessible_value_changed),
+                      obj);
+
+  obj->role = ATK_ROLE_SLIDER;
+}
+
+static void
+gtk_scale_button_accessible_notify_gtk (GObject    *obj,
+                                        GParamSpec *pspec)
+{
+  GtkScaleButton *scale_button;
+  GtkScaleButtonAccessible *accessible;
+
+  scale_button = GTK_SCALE_BUTTON (obj);
+  accessible = GTK_SCALE_BUTTON_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (scale_button)));
+
+  if (strcmp (pspec->name, "adjustment") == 0)
+    {
+      GtkAdjustment* adjustment;
+
+      adjustment = gtk_scale_button_get_adjustment (scale_button);
+      g_signal_connect (adjustment,
+                        "value-changed",
+                        G_CALLBACK (gtk_scale_button_accessible_value_changed),
+                        accessible);
+    }
+  else
+    {
+      GAIL_WIDGET_CLASS (gtk_scale_button_accessible_parent_class)->notify_gtk (obj, pspec);
+    }
+}
+
+static void
+gtk_scale_button_accessible_class_init (GtkScaleButtonAccessibleClass *klass)
+{
+  AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass);
+  GailWidgetClass *widget_class = GAIL_WIDGET_CLASS (klass);
+
+  atk_object_class->initialize = gtk_scale_button_accessible_initialize;
+
+  widget_class->notify_gtk = gtk_scale_button_accessible_notify_gtk;
+}
+
+static void
+gtk_scale_button_accessible_init (GtkScaleButtonAccessible *button)
+{
+}
+
+static gboolean
+gtk_scale_button_accessible_do_action (AtkAction *action,
+                                       gint       i)
+{
+  GtkWidget *widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
+  if (widget == NULL)
+    return FALSE;
+
+  if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
+    return FALSE;
+
+  switch (i)
+    {
+    case 0:
+      g_signal_emit_by_name (widget, "popup");
+      return TRUE;
+    case 1:
+      g_signal_emit_by_name (widget, "podown");
+      return TRUE;
+    default:
+      return FALSE;
+    }
+}
+
+static gint
+gtk_scale_button_accessible_get_n_actions (AtkAction *action)
+{
+  return 2;
+}
+
+static const gchar *
+gtk_scale_button_accessible_get_description (AtkAction *action,
+                                             gint       i)
+{
+  return NULL;
+}
+
+static const gchar *
+gtk_scale_button_accessible_action_get_name (AtkAction *action,
+                                             gint       i)
+{
+  switch (i)
+    {
+    case 0:
+      return "popup";
+    case 1:
+      return "popdown";
+    default:
+      return NULL;
+    }
+}
+
+static void
+atk_action_interface_init (AtkActionIface *iface)
+{
+  iface->do_action = gtk_scale_button_accessible_do_action;
+  iface->get_n_actions = gtk_scale_button_accessible_get_n_actions;
+  iface->get_description = gtk_scale_button_accessible_get_description;
+  iface->get_name = gtk_scale_button_accessible_action_get_name;
+}
+
+static void
+gtk_scale_button_accessible_get_current_value (AtkValue *obj,
+                                               GValue   *value)
+{
+  GtkWidget *widget;
+  GtkAdjustment *adjustment;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
+  if (adjustment == NULL)
+    return;
+
+  memset (value,  0, sizeof (GValue));
+  g_value_init (value, G_TYPE_DOUBLE);
+  g_value_set_double (value, gtk_adjustment_get_value (adjustment));
+}
+
+static void
+gtk_scale_button_accessible_get_maximum_value (AtkValue *obj,
+                                               GValue   *value)
+{
+  GtkWidget *widget;
+  GtkAdjustment *adjustment;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
+  if (adjustment == NULL)
+    return;
+
+  memset (value,  0, sizeof (GValue));
+  g_value_init (value, G_TYPE_DOUBLE);
+  g_value_set_double (value, gtk_adjustment_get_upper (adjustment));
+}
+
+static void
+gtk_scale_button_accessible_get_minimum_value (AtkValue *obj,
+                                               GValue   *value)
+{
+  GtkWidget *widget;
+  GtkAdjustment *adjustment;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
+  if (adjustment == NULL)
+    return;
+
+  memset (value,  0, sizeof (GValue));
+  g_value_init (value, G_TYPE_DOUBLE);
+  g_value_set_double (value, gtk_adjustment_get_lower (adjustment));
+}
+
+static void
+gtk_scale_button_accessible_get_minimum_increment (AtkValue *obj,
+                                                   GValue   *value)
+{
+  GtkWidget *widget;
+  GtkAdjustment *adjustment;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
+  if (adjustment == NULL)
+    return;
+
+  memset (value,  0, sizeof (GValue));
+  g_value_init (value, G_TYPE_DOUBLE);
+  g_value_set_double (value, gtk_adjustment_get_minimum_increment (adjustment));
+}
+
+static gboolean
+gtk_scale_button_accessible_set_current_value (AtkValue     *obj,
+                                               const GValue *value)
+{
+  GtkWidget *widget;
+  GtkAdjustment *adjustment;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
+  if (adjustment == NULL)
+    return FALSE;
+
+  gtk_adjustment_set_value (adjustment, g_value_get_double (value));
+
+  return TRUE;
+}
+
+static void
+atk_value_interface_init (AtkValueIface *iface)
+{
+  iface->get_current_value = gtk_scale_button_accessible_get_current_value;
+  iface->get_maximum_value = gtk_scale_button_accessible_get_maximum_value;
+  iface->get_minimum_value = gtk_scale_button_accessible_get_minimum_value;
+  iface->get_minimum_increment = gtk_scale_button_accessible_get_minimum_increment;
+  iface->set_current_value = gtk_scale_button_accessible_set_current_value;
+}
diff --git a/gtk/a11y/gtkscalebuttonaccessible.h b/gtk/a11y/gtkscalebuttonaccessible.h
new file mode 100644 (file)
index 0000000..442c55a
--- /dev/null
@@ -0,0 +1,52 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2008 Jan Arne Petersen <jap@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_SCALE_BUTTON_ACCESSIBLE_H__
+#define __GTK_SCALE_BUTTON_ACCESSIBLE_H__
+
+#include <gtk/gtk.h>
+#include "gailbutton.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SCALE_BUTTON_ACCESSIBLE                     (gtk_scale_button_accessible_get_type ())
+#define GTK_SCALE_BUTTON_ACCESSIBLE(obj)                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCALE_BUTTON_ACCESSIBLE, GtkScaleButtonAccessible))
+#define GTK_SCALE_BUTTON_ACCESSIBLE_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SCALE_BUTTON_ACCESSIBLE, GtkScaleButtonAccessibleClass))
+#define GTK_IS_SCALE_BUTTON_ACCESSIBLE(obj)                  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCALE_BUTTON_ACCESSIBLE))
+#define GTK_IS_SCALE_BUTTON_ACCESSIBLE_CLASS(klass)          (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SCALE_BUTTON_ACCESSIBLE))
+#define GTK_SCALE_BUTTON_ACCESSIBLE_GET_CLASS(obj)           (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SCALE_BUTTON_ACCESSIBLE, GtkScaleButtonAccessibleClass))
+
+typedef struct _GtkScaleButtonAccessible      GtkScaleButtonAccessible;
+typedef struct _GtkScaleButtonAccessibleClass GtkScaleButtonAccessibleClass;
+
+struct _GtkScaleButtonAccessible
+{
+  GailButton parent;
+};
+
+struct _GtkScaleButtonAccessibleClass
+{
+  GailButtonClass parent_class;
+};
+
+GType gtk_scale_button_accessible_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GTK_SCALE_BUTTON_ACCESSIBLE_H__ */
index 7a62baf418d4337374419a9acc26f4e916905edb..c56b73e7ef84f92dc5f5bdadcbfe266815d04dbb 100644 (file)
@@ -55,6 +55,7 @@
 #include "gtkwindow.h"
 #include "gtktypebuiltins.h"
 #include "gtkintl.h"
+#include "a11y/gtkscalebuttonaccessible.h"
 
 /**
  * SECTION:gtkscalebutton
@@ -343,6 +344,8 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
                                "popup", 0);
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
                                "popdown", 0);
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCALE_BUTTON_ACCESSIBLE);
 }
 
 static void